﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for orderDAL
/// </summary>
public class orderDAL
{
    DataAccess da;
	public orderDAL()
	{
		//
		// TODO: Add constructor logic here
		//
        da = new DataAccess();
	}
    public int addOrder(order order){
        SqlParameter[] paramList = new SqlParameter[6];
        paramList[0] = da.AddParameter("order_id", DBNull.Value, SqlDbType.Int);
        paramList[1] = da.AddParameter("customer_id",order.Customer_id, SqlDbType.Int);
        paramList[2] = da.AddParameter("order_status_id", order.Order_status_id, SqlDbType.Int);
        paramList[3] = da.AddParameter("currency_id", order.Currency_id, SqlDbType.Int);
        paramList[4] = da.AddParameter("coupon_id", order.Coupon_id, SqlDbType.Int);
        paramList[5] = da.AddParameter("total", order.Total, SqlDbType.Money);
        return da.executeUpdate("IS_Order", paramList);

    }
    public int addOrderProduct(order_product order_product)
    {
        SqlParameter[] paramList = new SqlParameter[6];
        paramList[0] = da.AddParameter("order_product_id", DBNull.Value, SqlDbType.Int);
        paramList[1] = da.AddParameter("order_id", order_product.Order_id, SqlDbType.Int);
        paramList[2] = da.AddParameter("product_id", order_product.Product_id, SqlDbType.Int);
        paramList[3] = da.AddParameter("name", order_product.Name, SqlDbType.NVarChar);
        paramList[4] = da.AddParameter("price", order_product.Price, SqlDbType.Int);
        paramList[5] = da.AddParameter("quantity", order_product.Quantity, SqlDbType.Int);
        return da.executeUpdate("IS_Order_Product", paramList);
    }
    public DataTable getOrderByCustomerID(int customer_id)
    {
        SqlParameter[] paramList = new SqlParameter[3];
        paramList[0] = da.AddParameter("order_id", DBNull.Value, SqlDbType.Int);
        paramList[1] = da.AddParameter("customer_id", customer_id, SqlDbType.Int);
        paramList[2] = da.AddParameter("date_added", DBNull.Value, SqlDbType.DateTime);
        
        return da.executeSelect("SELECT_Order", paramList);
    }
    public DataTable getOrderByOrderID(int order_id)
    {
        SqlParameter[] paramList = new SqlParameter[3];
        paramList[0] = da.AddParameter("order_id", order_id, SqlDbType.Int);
        paramList[1] = da.AddParameter("customer_id", DBNull.Value, SqlDbType.Int);
        paramList[2] = da.AddParameter("date_added", DBNull.Value, SqlDbType.DateTime);

        return da.executeSelect("SELECT_Order", paramList);
    }
    public DataTable getOrderByDateAdded(int Customer)
    {
        DateTime Date_added = DateTime.Now;
        SqlParameter[] paramList = new SqlParameter[3];
        paramList[0] = da.AddParameter("order_id", DBNull.Value, SqlDbType.Int);
        paramList[1] = da.AddParameter("customer_id", Customer, SqlDbType.Int);
        paramList[2] = da.AddParameter("date_added", Date_added, SqlDbType.DateTime);

        return da.executeSelect("SELECT_Order", paramList);
    }
    public DataTable getOrderbyCustomer_id(int customer_id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = da.AddParameter("customer_id", customer_id, SqlDbType.Int);
        return da.executeSelect("SelectOrderByCustomerId", paraList);
    }
    public DataTable getOrderProducbyOrder_id(int order_id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = da.AddParameter("order_id", order_id, SqlDbType.Int);
        return da.executeSelect("SelectOrderProductByOrderID", paraList);
    }
    

}